using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Common;
using Common.Knife4Swagger;
using Common.RefitHttp;
using Demo03.Repository;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Nacos.AspNetCore.V2;
using Nacos.V2;
using Nacos.YamlParser;
using Refit;
using Steeltoe.Extensions.Configuration.Placeholder;

var builder = WebApplication.CreateBuilder(args);
// 添加knife swagger
builder.AddKnifeSwagger(new Knife4UIConfig() { Title = "Demo03", Version = "v2", ProjectName = "Demo03.xml" });

// 配置
builder.AddConfiguration("application.yaml");

var assemblies = new List<Assembly>() { typeof(Program).Assembly };
// 使用autofac
builder.UseAutofac(assemblies);



// mysql
builder.Services.AddDbContextPool<AppDbContext>(b =>
{
    var connectionString = builder.Configuration.GetConnectionString("app");
    var serverVersion = ServerVersion.AutoDetect(connectionString);
    b.UseMySql(connectionString, serverVersion);
}, 64);

// nacos注册：使用yaml形式配置文件格式
builder.Host.UseNacosConfig("nacos", new YamlConfigurationStringParser());

builder.Services.AddNacosAspNet(builder.Configuration);

// 添加http支持
builder.AddRefitWithServiceDiscovery(typeof(Program).Assembly);

// 配置应用组件 
builder.SetupApplication();


var app = builder.Build();
app.ConfigurationApplication();

app.Run();